package com.idempotent.starter.token.impl;

import com.idempotent.starter.enums.TokenType;
import com.idempotent.starter.token.TokenService;

import java.util.Objects;

/**
 * Package: com.wyait.manage.idempotent.token
 * Description：
 * Author: huangjian
 * Date:  2020/9/13 18:18
 * Modified By:
 * @author huangjian
 */
public class TokenInGuavaCache extends TokenService {

    @Override
    public synchronized void putToken(String token) {
        CacheManager.put(token, token);
    }

    @Override
    public synchronized boolean verifyToken(String token) {
        if (Objects.isNull(CacheManager.get(token))) {
            return false;
        }
        if (!CacheManager.get(token).equals(token)) {
            return false;
        }
        CacheManager.remove(token);
        return true;
    }

    @Override
    public TokenType support() {
        return TokenType.GUAVA_CACHE;
    }
}
